
#import "PYImageProcessor.h"

@implementation PYImageProcessor

-(UIImage*)imageAtIndex:(NSUInteger)index withSize:(CGSize)imageSize
{
    NSDictionary* properties;
    CGImageRef image_ref = [[PYFileManager instance] newImageFromIndex:index imageType:kExtensionImage dictionary:&properties];
    CFNumberRef pixelWidth = (CFNumberRef)[properties objectForKey:(NSString*)kCGImagePropertyPixelWidth];
    
    NSNumber* pixelNumber;

    CFNumberGetValue(pixelWidth, kCFNumberNSIntegerType, pixelNumber);
    CGFloat scale = [pixelNumber floatValue] / imageSize.width;
    UIImageOrientation orientation = uiImageOrientationToApply((CFDictionaryRef)properties);
    UIImage* image = [UIImage imageWithCGImage:image_ref scale:scale orientation:orientation];
    CGImageRelease(image_ref);
    return image;
}

@end
